package classes.view.component
{
	import classes.controller.ENumber;
	import classes.controller.VONullObject;
	
	import com.d4p.custom.defaultButton.DefaultBtn;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class PopupFriend_listItem extends Sprite
	{
		private var _itemId:int;
		
		private var _name:TextField;
		private var _id:TextField;
		private var _currentLoc:TextField;
		private var _subject:TextField;
		private var _inBtn:DefaultBtn;
		private var _delBtn:DefaultBtn;
		private var _bg:Sprite;
		private var _roomID:String;
		private var _status:int;
		
		public function PopupFriend_listItem()
		{
			super();
			setLayOut();
			init();
		}
		public function itemIn($itemId:int, $name:String, $id:String, $currentLoc:int, $subject:String, $status:int):void
		{
			if($itemId%2 == 0) _bg.visible = false;
			
			this._status			= $status;
			this._itemId			= $itemId;
			
			this._name.text 		= VONullObject.getLoadInstance().nullText($name);
			this._id.text   		= VONullObject.getLoadInstance().nullText($id);
			
			if(($currentLoc == 0) || ($currentLoc ==- 1)){
				this._currentLoc.text	= "";
				_inBtn.visible = false;
			}else{
				this._currentLoc.text	= String($currentLoc);
				this._roomID = String($currentLoc);
			}
			
			this._subject.text		= VONullObject.getLoadInstance().nullText($subject);
		}
		
		public function get secret():int
		{
			return _status;
		}
		
		public function get id():int
		{
			return _itemId;
		}
		public function get roomID():String
		{
			return _roomID;
		}
		
		private function setLayOut():void
		{
			this._name 		= this.getChildByName('name_txt')		as TextField;
			this._id 		= this.getChildByName('id_txt')			as TextField;
			this._currentLoc= this.getChildByName('place_txt')		as TextField;
			this._subject 	= this.getChildByName('category_txt')	as TextField;
			this._inBtn 	= this.getChildByName('in_mc')			as DefaultBtn;
			this._delBtn 	= this.getChildByName('del_mc')			as DefaultBtn;
			this._bg		= this.getChildByName('bg_mc')			as Sprite;
		}
		
		private function init():void
		{
			this._inBtn.addEventListener(MouseEvent.CLICK,		onClickHandler);
			this._delBtn.addEventListener(MouseEvent.CLICK,		onClickHandler);
		}
		private function onClickHandler(e:MouseEvent):void
		{
			switch(e.currentTarget){
				case _inBtn :
					dispatchEvent(new ENumber(0, ENumber.EVENT_NUMBER));
					break;
				case _delBtn :
					dispatchEvent(new ENumber(1, ENumber.EVENT_NUMBER));
					break;
			}
		}
		
		
	}
}